package com.wxw;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

/**
 * 读取外部IP的地址位置
 * @author R&D-IOT
 *
 */
public class GetIPAddress {

	
	
    public static String  getAddress(){
        RestTemplate restTemplate = new RestTemplate();
        String  result ="";
        try{
            String url = String.format("https://api.ipgeolocation.io/ipgeo?apiKey=5b5e989e16cb476488fbce54d00a15fb&ip=14.120.51.235");
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
            ResponseEntity<String> response = restTemplate.getForEntity( url, String.class);
            result = response.getBody() ;
 
        } catch (Exception e){
             result= "error";
        }
        return result;
    }
    
    public static void main(String[] args) {
    	GetIPAddress getAdd = new GetIPAddress();
		String res = getAdd.getAddress();
		System.out.print("-----------------------------");
    	System.out.print(res);
    	
    }
}
